{extend name="platform/base" /}
{block name="resources"/}
<style>

</style>

{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 购物设置 </header>
	<div class="panel-body">
		<form class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">自动收货时间</label>
				<div class="col-md-4">
					<input id="order_auto_delinery" type="number" min="0.00" step="1.00" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')" value="{$shopSet['order_auto_delinery']}" style="margin-bottom: 10px;width: 100%;padding: 6px 12px;">
					<br/><a class="hint" style="color:#BBB;">订单多长时间后自动收货，单位为/天</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">订单自动关闭时间</label>
				<div class="col-md-4">
					<input id="order_buy_close_time" type="number" min="0.00" step="1.00" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')" value="{$shopSet['order_buy_close_time']}" style="margin-bottom: 10px;width: 100%;padding: 6px 12px;">
					<br/><a class="hint" style="color:#BBB;">订单开始后多长时间未付款自动关闭，单位为/分钟(注：不填写或0默认关闭时间为60分钟)</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否开启余额支付</label>
				<div class="col-md-4">
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="order_balance_pay" value="1" {if condition="$shopSet['order_balance_pay'] eq 1"}checked="checked"{/if} id="balanceResultYes">启用</label> 
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="order_balance_pay" value="0" {if condition="$shopSet['order_balance_pay'] eq 0"}checked="checked"{/if} id="balanceResultNo">禁用</label>
					<input type="hidden" id="is_open" value="{$shopSet['order_balance_pay']}">
					<br/><a class="hint" style="color:#BBB;">是否开启余额支付</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否开启货到付款</label>
				<div class="col-md-4">
					<label class="radio inline"><input type="radio" name="order_delivery_pay" value="1"  id="payResultYes" {if condition="$shopSet['order_delivery_pay'] eq 1"}checked{/if}>启用</label> 
					<label class="radio inline"><input type="radio" name="order_delivery_pay" value="0"  id="payResultNo"  {if condition="$shopSet['order_delivery_pay'] eq 0"}checked{/if}>禁用</label>
					<br/><a class="hint" style="color:#BBB;">是否支持货到付款</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">订单完成时间</label>
				<div class="col-md-4">
					<select id="order_delivery_complete_time" style="width:100%;padding:6px 12px;margin-bottom:10px;">
						<option id = 'closeday0' value="0" {if condition="$shopSet['order_delivery_complete_time'] eq 0"}selected="selected"{/if}>&nbsp;&nbsp;立即</option>
						<option id = 'closeday1' value="1" {if condition="$shopSet['order_delivery_complete_time'] eq 1"}selected="selected"{/if}>&nbsp;&nbsp;1天</option>
						<option id = 'closeday2' value="2" {if condition="$shopSet['order_delivery_complete_time'] eq 2"}selected="selected"{/if}>&nbsp;&nbsp;2天</option>
						<option id = 'closeday3' value="3" {if condition="$shopSet['order_delivery_complete_time'] eq 3"}selected="selected"{/if}>&nbsp;&nbsp;3天</option>
						<option id = 'closeday4' value="4" {if condition="$shopSet['order_delivery_complete_time'] eq 4"}selected="selected"{/if}>&nbsp;&nbsp;4天</option>
						<option id = 'closeday5' value="5" {if condition="$shopSet['order_delivery_complete_time'] eq 5"}selected="selected"{/if}>&nbsp;&nbsp;5天</option>
						<option id = 'closeday6' value="6" {if condition="$shopSet['order_delivery_complete_time'] eq 6"}selected="selected"{/if} >&nbsp;&nbsp;6天</option>
						<option id = 'closeday7' value="7" {if condition="$shopSet['order_delivery_complete_time'] eq 7"}selected="selected"{/if}>&nbsp;&nbsp;7天</option>
  					</select>
  					<input type="hidden" id="closeday" value="{$shopSet['order_delivery_complete_time']}">
  					<br/><a class="hint" style="color:#BBB;">收货后，多少时间订单自动完成，单位为/天</a>
				</div>
			</div>
           
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否显示购买记录</label>
				<div class="col-md-4">
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="order_show_buy_record" value="1" {if condition="$shopSet['order_show_buy_record'] eq 1"}checked="checked"{/if} id="purchaseRecordYes">启用</label> 
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="order_show_buy_record" value="0" {if condition="$shopSet['order_show_buy_record'] eq 0"}checked="checked"{/if} id="purchaseRecordNo">禁用</label><br/>
					<input type="hidden" id="or_open" value="{$shopSet['order_show_buy_record']}">
					<a class="hint" style="color:#BBB;">是否显示购买记录</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否开启买家自提</label>
				<div class="col-md-4">
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="buyer_self_lifting" value="1" {if condition="$shopSet['buyer_self_lifting'] eq 1"}checked="checked"{/if} id="sinceYes">启用</label> 
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="buyer_self_lifting" value="0" id="sinceNo" {if condition="$shopSet['buyer_self_lifting'] eq 0"}checked="checked"{/if}>禁用</label><br/>
					<input type="hidden" id="is_start" value="{$shopSet['buyer_self_lifting']}">
					<a class="hint" style="color:#BBB;">是否启用买家自提</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否开启商家配送</label>
				<div class="col-md-4">
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="seller_dispatching" value="1" {if condition="$shopSet['seller_dispatching'] eq 1"}checked="checked"{/if} id="dispatchingYes">启用</label> 
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="seller_dispatching" value="0" {if condition="$shopSet['seller_dispatching'] eq 0"}checked="checked"{/if} id="dispatchingNo">禁用</label>
					<input type="hidden" id="is_dispatching" value="{$shopSet['seller_dispatching']}">
					<br/><a class="hint" style="color:#BBB;">是否启用商家配送</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否允许选择物流</label>
				<div class="col-md-4">
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="is_logistics" value="1" checked="checked" id="logisticsYes">启用</label> 
					<label class="radio inline" style="margin-bottom:10px;"><input type="radio" name="is_logistics" value="0" id="logisticsNo">禁用</label>
					<input type="hidden" id="is_logistics" value="{$shopSet['is_logistics']}">
					<br/><a class="hint" style="color:#BBB;">是否允许用户选择物流</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">购物返积分设置:</label>
				<div class="col-sm-4">
					<select id="shopping_back_points" style="margin-bottom:10px;width:100%;padding:6px 12px;">
						<option  value="1" {if condition="$shopSet['shopping_back_points'] eq 1"}selected{/if}>&nbsp;&nbsp;订单已完成</option>
						<option  value="2" {if condition="$shopSet['shopping_back_points'] eq 2"}selected{/if}>&nbsp;&nbsp;已收货</option>
						<option  value="3" {if condition="$shopSet['shopping_back_points'] eq 3"}selected{/if}>&nbsp;&nbsp;支付完成</option>
  					</select>
  					<br/><a class="hint" style="color:#BBB;">购物返积分设置</a>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">发票税率:</label>
				 <div class="col-sm-4">
					<input id="order_invoice_tax" type="number" min="0.00" step="0.01" value="{$shopSet['order_invoice_tax']}" style="margin-bottom:10px;width:100%;padding:6px 12px;"/>
					<br/><a class="hint" style="color:#BBB;">设置开发票的税率，单位为%</a>
		 	     </div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">发票内容</label>
				 
				 <div class="col-sm-4">
					<textarea  rows="2" id="order_invoice_content" class="textarea w400" style="width:100%;height:150px;margin-bottom:10px;">{$shopSet['order_invoice_content']}</textarea>
				    <br/><a class="hint" style="color:#BBB;">客户要求开发票时可以选择的内容，逗号分格代表一个选项，例如：办公用品,明细</a>
				</div>
			</div>
			
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="setConfigAjax()" class="btn btn-primary">保存</a>
				</div>
			</div>
		</form>
	</div>
</section>
<script>
var validation = true;//验证余额输入
$("#order_invoice_tax").keyup(function(){
	var reg = /^\d+(.{0,1})(\d{0,2})$/;
	if(!reg.test($(this).val())){
		showTip("请输入大于0的数字，并且保留两位小数","warning");
		validation = false;
	}else{
		validation = true;
	}
})

	window.onload=function(){
		var is_open = $("#is_open").val();
		if(is_open == ''){
			is_open = 0;
		}
		if(parseInt(is_open) == 0){
			$("#balanceResultNo").prop("checked","checked");
		}else{
			$("#balanceResultYes").prop("checked","checked");
		}
		
		var or_open = $("#or_open").val();
		if(or_open == ''){
			or_open = 0;
		}
		//alert(or_open);
		if(parseInt(or_open) == 0){
			$("purchaseRecordNo").prop("checked","checked");
		}else{
			$("#purchaseRecordYes").prop("checked","checked");
		}
		
		var closeday = $("#closeday").val();
		//alert(closeday);
		$("#closeday"+closeday).attr("selected", true);
		
		var is_start = $("#is_start").val();
		if(is_start == ''){
			is_start = 0;
		}
		if(parseInt(is_start) == 0){
			$("#sinceNo").prop("checked","checked");
		}else{
			$("#sinceYes").prop("checked","checked");
		}
		
		var is_dispatching = $("#is_dispatching").val();
		if(is_dispatching == ''){
			is_dispatching = 0;
		}
		if(parseInt(is_dispatching) == 0){
			$("#dispatchingNo").prop("checked","checked");
		}else{
			$("#dispatchingYes").prop("checked","checked");
		}
		var is_logistics = $("#is_logistics").val();
		if(is_logistics == ''){
			is_logistics = 0;
		}
		if(parseInt(is_logistics) == 0){
			$("#logisticsNo").prop("checked","checked");
		}else{
			$("#logisticsYes").prop("checked","checked");
		}
		
	};
	function setConfigAjax(){
		var order_delivery_complete_time = $('#order_delivery_complete_time').val();
		var order_buy_close_time = $('#order_buy_close_time').val();
		var order_balance_pay = $("input[type='radio'][name='order_balance_pay']:checked").val();
		var order_delivery_pay = $("input[type='radio'][name='order_delivery_pay']:checked").val();
		var order_auto_delinery = $("#order_auto_delinery").val();
		var order_show_buy_record = $("input[type='radio'][name='order_show_buy_record']:checked").val();
		var buyer_self_lifting = $("input[type='radio'][name='buyer_self_lifting']:checked").val();
		var seller_dispatching = $("input[type='radio'][name='seller_dispatching']:checked").val();
		var is_logistics = $("input[type='radio'][name='is_logistics']:checked").val();
		var order_invoice_tax = $("#order_invoice_tax").val();
		var order_invoice_content = $("#order_invoice_content").val();
		var shopping_back_points = $("#shopping_back_points").val();
		 $.ajax({
			type:"post",
			url:"{:__URL('PLATFORM_MAIN/config/shopset')}",
			data:{
				"order_delivery_complete_time" : order_delivery_complete_time,
				"order_buy_close_time":order_buy_close_time,
				"order_balance_pay" : order_balance_pay,
				"order_delivery_pay" : order_delivery_pay,
				"order_auto_delinery" : order_auto_delinery,
				"order_show_buy_record" : order_show_buy_record,
				"buyer_self_lifting" : buyer_self_lifting,
				"seller_dispatching" : seller_dispatching,
				"order_invoice_tax" : order_invoice_tax,
				"is_logistics" : is_logistics,
				"order_invoice_content" : order_invoice_content,
				"shopping_back_points" : shopping_back_points
			},
			async:true,
			success:function (data) {
				if (data["code"] > 0) {
					showMessage('success', data["message"],"{:__URL('PLATFORM_MAIN/config/shopset')}");
				}else{
					showMessage('error', data["message"]);
				}	
			}
		}); 
	}
</script>
{/block}